package com.accenture.adf.newcodington.module6.sample;

/**
 * 
 * CodingtonEventPass is about buying an entry pass which can be used to attend 
 * various events taking place in New Codington
 * 
 * TryIt 1:- Creation of a class 
 * Instructions: 
 * 1. Create a class named 'CodingtonEventPass_TryIt1' with main() method and print 
 * "Hello New Codington Visitors!" message to the console     
 * 
 * 
 * TryIt 2:- Creating constants and variables of different data types
 * Instructions:
 * 1. Declare a private static final float variable for children fare and initialize it between class declaration and main() method
 * 2. On the next line, declare a private static final float variable for adults fare and initialize it 
 * 3. Create variables of different data types used in calculating the fare for event pass inside main() method
 *    a. Declare an integer variable for number of children attending the event
 *    b. Declare an integer variable for number of adults attending the event 
 *    c. Declare a double variable for total fare 
 *    
 * 
 * TryIt 3:- Usage of basic arithmetic operators
 * Instructions:
 * 1. Declare a double variable for total children fare
 * 2. Declare a double variable for total adults fare
 * 3. Initialize the following variables: 
 *    a. number of children
 *    b. number of adults
 * 4. Calculate total children fare by multiplying number of children with children fare
 * 5. Calculate total adults fare by multiplying number of adults with adults fare
 * 6. Print total children fare to the console
 * 7. Print total adults fare to the console
 * 8. Calculate total ticket fare by adding total children fare with total adult fare
 * 9. Print total fare to the console
 * 
 * 
 * TryIt 4:- Usage of If/Else structure 
 * Instructions:
 * 1. Declare a boolean variable for evening pass or regular pass
 * 		a. Regular pass can be used between 9 AM till 5 PM
 * 		b. Evening pass can be used between 5 PM till 9 PM
 * 2. Initialize new declared variables for evening pass
 * 3. Use If / Else structure to check for evening pass and print appropriate message to the console
 * 4. If evening pass, print message "Evening pass hours are from 5 PM - 9 PM, additional evening charge applicable for each pass"
 * 5. If regular pass, print message "Regular pass hours are from 9 AM - 5 PM, no additional charge applicable"
 *      
 * 
 * TryIt 5:- Usage of binary operators
 * Instructions:
 * 1. Declare a short variable to identify pass validity
 *    a. A pass can be valid for 1 day, 3 days or 5 days
 * 2. Initialize newly declared variable for pass validity
 * 3. Use If / Else to verify evening pass and pass validity and print appropriate message to the console
 * 		a. For evening pass and 1 day duration, print "Use of an evening pass incurs additional
 *         charge for each ticket." 
 * 		b. For evening pass and 3 or 5 day duration, print "Use of an Evening pass incurs an 
 *         additional charge, a discount is provided for use of an 3 or 5 day pass." 
 * 		c. For any pass duration that is not equal to 1, 3 or 5, print "Please choose either 1,
 *         3 or 5 days for pass duration." 
 *    	d. otherwise, print "Regular pass offers discount based on pass duration."
 * 
 * 
 * TryIt 6:- Usage of switch-case structure
 * Instructions:
 * 1. Modify If / Else to verify only evening pass or regular pass and print appropriate message to the console
 *    	a. For evening pass, print 'Use of an evening pass incurs an additional charge.'
 *    	b. Otherwise, print 'No additional charge for use of a regular pass.'
 * 2. Use Switch-Case to verify pass duration and print appropriate message to the console
 * 		a. On choosing a 1 day pass, print 'No discount on 1 day pass' 
 * 		b. On choosing a 3 day pass, print '3 day pass offers 15% discount' 
 * 		c. On choosing a 5 day pass, print '5 day pass offers 25% discount'
 * 		d. If an invalid option is chosen print 'Please choose only 1, 3 or 5 for valid pass duration.' 
 * 
 * 
 * TryIt 7:- Usage of for loop and while loop 
 * Instructions:
 * 1. Use for loop to generate travel pass id with number of tickets issued as upper bound
 * 		a. Declare an integer variable for travel pass id
 * 		b. Travel pass id can be generated by simply incrementing the loop index by 1
 * 		c. Print travel pass id to the console along with loop index
 * 2. Declare a temporary index variable and initialize it to zero in main() method
 * 3. Use while loop to generate travel pass id with number of tickets issued as upper bound
 *		a. Declare an integer variable for travel pass id
 * 		b. Travel pass id can be generated by simply incrementing the loop index by 1
 * 		c. Print travel pass id to the console along with loop index
 * 		d. Increase index by 1 for next iteration
 * 4. Comment out for loop to demonstrate while loop and vice versa
 *
 * 
 * TryIt 8:- Arrays and population of single dimensional array using for loop
 * Instructions:
 * 1. Declare an integer single dimensional array for travel pass sequence numbers inside main() method
 *    a. Initialize travel pass array with size as number of tickets
 * 2. Modify for loop to assign pass id's to travel pass array in respective indexes
 * 3. Modify while loop as a do..while loop with upper bound as travel pass array length
 * 		a. Remove pass id generation logic
 * 		b. Print array values along with array index to console
 * 
 * 
 * TryIt 9:- Methods, parameters and return types. 
 * Instructions:
 * 1. Define a static method to calculate total fare based on evening pass or regular pass (evening pass flag as parameter for the method)
 * 2. Specify return type for the new method as String
 * 3. Move If / Else logic to the new method
 * 4. Declare a String variable to capture return message from If or Else
 * 5. Modify If and Else conditions to set the return message to the string variable
 * 6. Return the string message to main() method instead of printing to console  
 * 7. Define method to calculate total fare based on pass validity (pass validity as the parameter for the method)
 * 8. Specify return type for the new method as String    
 * 9. Move Switch-Case logic to the new method
 * 10.Modify Case statements to return message to the main () method  
 * 11. Declare a string variable in the main() method to capture the return message from the each of the above methods
 * 12. Invoke method for weekend check and print the return message to console
 * 13. Invoke method for travel class check and print the return message to console
 * 
 */

public class CodingtonEventPass_TryIt {
	
	private static final float CHILDREN_FARE = 5; //Try with different values
	private static final float ADULTS_FARE = 8; //Try with different values
	
	public static void main(String[] args){
			
		int noOfChildren;
		int noOfAdults;		
		double totalChildrenFare;
		double totalAdultsFare;
		double totalFare;
		
		boolean eveningPass;
		short passValidity;
		String result;
				
		noOfChildren = 2; //Try with different values
		noOfAdults = 2;	//Try with different values

		totalChildrenFare = noOfChildren * CHILDREN_FARE;
		totalAdultsFare = noOfAdults * ADULTS_FARE;
		
		System.out.println("Hello New Codington Visitors!");
		System.out.println("Total Children Fare: " + totalChildrenFare);
		System.out.println("Total Adults Fare: " + totalAdultsFare);
		
		totalFare = (noOfChildren * CHILDREN_FARE) + (noOfAdults * ADULTS_FARE);
						
		System.out.println("Base Fare: "+totalFare);

		eveningPass = true; //Try changing values true or false
		passValidity = 3; //Try changing values between 1, 3 or 5
		
		result = checkIfEveningPass(eveningPass);
		System.out.println(result);
		
		result = checkPassValidity(passValidity);
		System.out.println(result);
		
		int[] travelPass = new int[noOfChildren + noOfAdults];
		
		//Populate single dimensional array
		for(int i=0;i<travelPass.length;i++){
			int passID = i + 1;
			travelPass[i] = passID;
		}
		
		//Print array values
		System.out.println();
		System.out.println("Travel Pass Ids:");
		int index = 0;
		do{
			System.out.println("\tID " + (index+1) + ": " + travelPass[index]);
			index++;
		}while(index < travelPass.length);
	}
	
	/**
	 * Method checks for evening pass and regular pass and returns appropriate message to main() method
	 * @param eveningPass - flag indicates pass issued is a evening pass or regular pass
	 * @return message - based on evening or regular pass appropriate message will be returned to main() method
	 */
	public static String checkIfEveningPass(boolean eveningPass){		
		String message;
		if(eveningPass){
			message = "Use of an evening pass incurs an additional charge.";	
		}else{
			message = "No additional charge for use of a regular pass.";
		}	
		return message;
	}
	
	/**
	 * Method checks for pass duration 1 day, 3 days or 5 days and returns appropriate message to main() method
	 * @param passValidity - validity could be 1 for 1 day pass, 3 for 3 day pass and 5 for 5 day pass
	 * @return - returns appropriate message to main() method based on the duration
	 */
	public static String checkPassValidity(short passValidity){		
		
		switch(passValidity){
		
			case 1: return "No discount on 1 day pass.";					
			
			case 3: return "3 day pass offers 15% discount.";
			
			case 5: return "5 day pass offers 25% discount.";					
			
			default: return "Please choose only 1, 3 or 5 days for valid pass duration.";		
		}
	}	
		
}
